using System;
using System.Collections.Generic;
using System.Text;
using ALib;

namespace TradingPlatform
{
    public class TickerNameAndId
    {
        private readonly List<string> _tickerNames;

        public int Count
        {
            get
            {
                int result = _tickerNames.Count;
                return result;
            }
        }

        public TickerNameAndId()
        {
            _tickerNames = new List<string>();
        }

        public void Add(string tickerName)
        {
            if (!Contains(tickerName))
            {
                _tickerNames.Add(tickerName);
            }
        }

        public bool Contains(string tickerName)
        {
            bool result = _tickerNames.Contains(tickerName);
            return result;
        }

        public int GetId(string tickerName)
        {
            GoodValue.Assert(Contains(tickerName));

            int result = _tickerNames.IndexOf(tickerName) +1;
            return result;
        }

        public string GetTickerName(int id)
        {
            GoodValue.Assert(1<=id&&id<=_tickerNames.Count);
            string result = _tickerNames[id - 1];
            return result;
        }

        public static string ToTickerName(string exchange, string secType, string symbol, string expiry, string currency)
        {
            string result = string.Format(@"{0}@{1}@{2}@{3}@{4}", exchange, secType, symbol, expiry, currency);
            return result;
        }

        public static string[] ToContractInfo(string tickerName)
        {
            string[] result = tickerName.Split(new char[] {'@'});
            GoodValue.Assert(result.Length == 5);
            return result;
        }
    }
}